package com.cdut.logistics.action.system;

import com.cdut.logistics.intercepter.system.AuthorityIntercepter;
import com.cdut.logistics.model.entity.system.Authority;
import com.cdut.logistics.service.impl.system.AuthorityServiceImp;
import com.cdut.logistics.service.interf.system.AuthorityService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 
 * @ClassName: AuthorityController  
 * @Description: TODO(权限的action)  
 * @author lxh
 * @date 2018年1月28日 下午2:22:56
 */
@Before(AuthorityIntercepter.class)
public class AuthorityController extends Controller {
	private AuthorityService authorityserviceimp=new AuthorityServiceImp();
	/**
	 * 	
	 * @Title: addAuthority  
	 * @Description: TODO(增加权限)
	 * @author lxh
	 * @throws
	 */
	public void addAuthority(){
		String name=getPara("name");
		String url=getPara("url");
		String is_use="1";
		String active="1";
		Date created=new Date();
		boolean result =authorityserviceimp.addAuthority(name,url,is_use,active,created);
		setAttr("result",result);
		renderJson();
	}
	/**
	 * 
	 * @Title: updateAuthority  
	 * @Description: TODO(修改权限)
	 * @author lxh
	 * @throws
	 */
	public void updateAuthority(){
		String id=getPara("id");
		String name=getPara("name");
		String url=getPara("url");
		Date updated=new Date();
		boolean result=authorityserviceimp.updateAuthority(id, name, url,updated);
		setAttr("result",result);
		renderJson();
	}
	/**
	 * 
	 * @Title: deleteAuthority  
	 * @Description: TODO(逻辑删除权限，即把active设置隈0)
	 * @author lxh
	 * @throws
	 */
	public void deleteAuthority(){
		String id=getPara("id");
		boolean result=authorityserviceimp.deleteAuthority(id);
		setAttr("result",result);
		renderJson();
	}
	/**
	 * 
	 * @Title: queryAuthority  
	 * @Description: TODO(查询权限)
	 * @author lxh
	 * @throws
	 */
	public  void queryAuthorityById(){
		String id=getPara("id");
		Authority result=authorityserviceimp.queryAuthorityById(id);
		setAttr("result",result);
		renderJson();
	}
	/**
	 * 
	 * @Title: queryAllAuthority  
	 * @Description: TODO(查询所有权限信息)
	 * @author lxh
	 * @throws
	 */
	public void queryAllAuthority(){
		List<Authority> authorityList=authorityserviceimp.queryAllAuthority();
		setAttr("authorityList",authorityList);
		renderJson();
	}
	/**
	 * 
	 * @Title: userAuthorityId  
	 * @Description: TODO(用户注册时生成普通用户authority_id)
	 * @author lxh
	 * @return
	 * @throws
	 */
	public int userAuthorityId(){
		int authority_id=5;
		return authority_id;
	}
	/**
	 * 
	 * @Title: adminAuthorityId  
	 * @Description: TODO(用户注册时生成管理员authority_id)
	 * @author lxh
	 * @return
	 * @throws
	 */
	public int adminAuthorityId(){
		int authority_id=1;
		return authority_id;
	}
	/**
	 * 
	 * @Title: repairMemAuthorityId  
	 * @Description: TODO(用户注册时生成维修人员authority_id)
	 * @author lxh
	 * @return
	 * @throws
	 */
	public int repairMemAuthorityId(){
		int authority_id=3;
		return authority_id;
	}
	/**
	 * 
	 * @Title: repairLeaderAuthorityId  
	 * @Description: TODO(用户注册时生成维修组长authority_id)
	 * @author lxh
	 * @return
	 * @throws
	 */
	public int repairLeaderAuthorityId(){
		int authority_id=2;
		return authority_id;
	}
	/**
	 * 
	 * @Title: operationMemAuthorityId  
	 * @Description: TODO(用户注册时生成运维人员authority_id)
	 * @author lxh
	 * @return
	 * @throws
	 */
	public int operationMemAuthorityId(){
		int authority_id=4;
		return authority_id;
	}
	/**
	 * 
	 * @Title: ifAuthority  
	 * @Description: TODO(返回权限列表)
	 * @author lxh
	 * @throws
	 */
	public void ifAuthority(){
		int authority_id=0;
		try {
			authority_id = Integer.valueOf(getPara("authority_id"));
		} catch (Exception e) {
			renderJson();
		}
		Map<String,Integer> m =authorityserviceimp.queryIfAuthority(authority_id);
		setAttr("autho_list", m);
		renderJson();
	}
}